<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.2.1.js"></script>
    <style>
        *{margin: 0;padding: 0;}
        body{
            height: 2000px;
        }
        .nav{
           line-height: 50px;
           background-color: orangered;
           text-align: center;
           opacity: 0;
           width: 100%;
           position: fixed;
            
        }
    </style>
</head>
<body>
    <div class="nav">
        故宫
    </div>
    <script>
        $(window).scroll(function(){
            let scrollTop = $(window).scrollTop();
            let opacity = scrollTop/400;

            if(opacity>1){
                opacity = 1;
            }

            $(".nav").css({opacity:opacity});
        })
    </script>
</body>
</html>